package com.leo.erp.web.msg;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.leo.erp.dto.MsgExecution;
import com.leo.erp.enums.MsgStateEnum;
import com.leo.erp.service.MsgService;
import com.leo.erp.util.HttpServletRequestUtil;

@Controller
@RequestMapping(value = "/msg")
public class MsgManagementController {
	@Autowired
	private MsgService msgService;
	
	@RequestMapping(value = "/getMsgCountByStatus")
	@ResponseBody
	public Map<String, Object> getMsgCountByStatus(HttpServletRequest request){
		Map<String, Object> modelMap = new HashMap<>();
		//获取前台传过来的值
		String status = HttpServletRequestUtil.getString(request, "status");
		MsgExecution me = msgService.getMsgCountByStatus(status);
		if(me.getState() == MsgStateEnum.SUCCESS.getState()) {
			int count = me.getCount();
			modelMap.put("success", true);
			modelMap.put("count", count);
		}else {
			modelMap.put("success", false);
			modelMap.put("msg", "获取数据失败");
		}
		
		return modelMap;
	}
}
